$(function() {
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getbaicaijiatitle",
        // data: "data",
        dataType: "json",
        success: function(response) {
            //创建标签页模板
            var biaoqian = template('bc_biaoqian', response);
            //给其插入模板结构
            $('.nav-tabs').html(biaoqian);
            //创建标签页导航模板
            var biaoqian_daohang = template('moban_daohang', response);
            // 给其插入模板结构
            $('#biaoqian_daohang').html(biaoqian_daohang);
            //声明一个变量
            var biaoqian_kuan = 0;
            //获取所有动态生成的li遍历每个li的宽度相加
            $('.nav-tabs li').each(function(indexInArray, valueOfElement) {
                biaoqian_kuan += $(this).outerWidth(true)
            });
            //把li的总宽度给其父元素
            $('.nav-tabs').width(biaoqian_kuan);
        }
    });
    var titleid = 0;
    $('.nav-tabs')[0].addEventListener('touchstart', function(event) {
        titleid = $(event.target.parentNode).data('titleid')
        shuju(titleid);
    })

    function shuju(titleid) {
        $.ajax({
            type: "get",
            url: "http://193.112.55.79:9090/api/getbaicaijiaproduct",
            data: { titleid: titleid },
            dataType: "json",
            success: function(response) {
                var html = template('moban_shuju', response);
                $('.tab-pane').html(html)
            }
        });
    }
    shuju(titleid);

})